package com.codedancer.campus.mapper;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.School;
import com.codedancer.campus.qo.school.SchoolPageSearchQo;
import java.util.List;

public interface SchoolMapper extends BaseMapper<School> {

    /**
     * 分页查询学校
     *
     * @param schoolPage
     * @param schoolPageSearchQo
     * @return
     */
    default IPage<School> page(Page<School> schoolPage, SchoolPageSearchQo schoolPageSearchQo) {
        LambdaQueryWrapper<School> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(schoolPageSearchQo.getName())) {
            lambdaQueryWrapper.like(School::getName, schoolPageSearchQo.getName());
        }
        if (ObjectUtil.isNotEmpty(schoolPageSearchQo.getDisabled())) {
            lambdaQueryWrapper.eq(School::getDisabled, schoolPageSearchQo.getDisabled());
        }
        return selectPage(schoolPage, lambdaQueryWrapper);
    }

    /**
     * 获取全部学校(未删除和已启用)
     *
     * @return
     */
    default List<School> allNoDeleteAndEnable() {
        LambdaQueryWrapper<School> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(School::getDisabled, false);
        lambdaQueryWrapper.eq(School::getDeleted, 0);
        return selectList(lambdaQueryWrapper);
    }
}
